<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" encoding="ISO-8859-1" indent="yes"/>
	<xsl:template match="/">
		<database>
			<xsl:attribute name="name">
				<xsl:value-of select="translate(Db/@nm, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
			</xsl:attribute>
			<xsl:attribute name="defaultIdMethod">native</xsl:attribute>
			<xsl:for-each select="Db/Sch/Tbl">
				<table>
					<xsl:attribute name="name">
						<xsl:value-of select="@nm"/>
					</xsl:attribute>
					<xsl:attribute name="description">
						<xsl:value-of select="concat('Table ', @nm)"/>
					</xsl:attribute>
					<xsl:for-each select="Cl">
						<column>
							<xsl:attribute name="name">
								<xsl:value-of select="@nm"/>
							</xsl:attribute>
							<xsl:attribute name="type">
								<xsl:choose>
									<xsl:when test="DT/@ds = 'Enum'">varchar</xsl:when>
									<xsl:when test="DT/@ds = 'DateTime'">timestamp</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="translate(DT/@ds,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:attribute>
							<xsl:choose>
								<xsl:when test="DT/@ln != 'null'">
									<xsl:attribute name="size">
										<xsl:value-of select="DT/@ln"/>
									</xsl:attribute>
								</xsl:when>
								<xsl:when test="DT/@ds = 'Enum'">
									<xsl:attribute name="size">
										<xsl:value-of select="string-length(DT/@en)"/>
									</xsl:attribute>
								</xsl:when>
							</xsl:choose>
							<!--							<xsl:if test="DT/@ln != 'null'">
								<xsl:attribute name="size">
									<xsl:value-of select="DT/@ln"/>
								</xsl:attribute>
							</xsl:if>-->
							<xsl:attribute name="require">
								<xsl:choose>
									<xsl:when test="@nu = '0'">true</xsl:when>
									<xsl:when test="@nu = '1'">false</xsl:when>
								</xsl:choose>
							</xsl:attribute>
							<xsl:if test="../Pk/@ClNs = @nm">
								<xsl:attribute name="primaryKey">true</xsl:attribute>
							</xsl:if>
							<xsl:if test="@au = '1'">
								<xsl:attribute name="autoIncrement">true</xsl:attribute>
							</xsl:if>
							<xsl:if test="DT/@ds = 'Enum'">
								<xsl:attribute name="description">
									<xsl:value-of select="DT/@en"/>
								</xsl:attribute>
							</xsl:if>
						</column>
					</xsl:for-each>
					<xsl:if test="Fk">
						<xsl:for-each select="Fk">
							<foreign-key>
								<xsl:attribute name="name">
									<xsl:value-of select="@nm"/>
								</xsl:attribute>
								<xsl:attribute name="foreignTable">
									<xsl:value-of select="PrTb/@nm"/>
								</xsl:attribute>
								<reference>
									<xsl:attribute name="local">
										<xsl:value-of select="ClPr/@cdCl"/>
									</xsl:attribute>
									<xsl:attribute name="foreign">
										<xsl:value-of select="ClPr/@prCl"/>
									</xsl:attribute>
								</reference>
							</foreign-key>
						</xsl:for-each>
					</xsl:if>
				</table>
			</xsl:for-each>
		</database>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="siprea.xml" htmlbaseurl="" outputurl="schema.xml" processortype="internal" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="DVBLOX&#x2D;DB&#x2D;2.xml" srcSchemaRoot="Db" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition><template match="/"><block path="database/xsl:for&#x2D;each" x="265" y="72"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each" x="265" y="126"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:attribute[1]/xsl:value&#x2D;of" x="225" y="31"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:if/!=[0]" x="59" y="69"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:if" x="105" y="71"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:attribute[2]/xsl:choose" x="195" y="150"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:attribute[2]/xsl:choose/=[0]" x="149" y="144"/><block path="" x="25" y="71"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:attribute[2]/xsl:choose/=[1]" x="149" y="172"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:if[1]/=[0]" x="219" y="29"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:if[1]" x="265" y="31"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:if[2]/=[0]" x="259" y="29"/><block path="database/xsl:for&#x2D;each/table/xsl:for&#x2D;each/column/xsl:if[2]" x="305" y="31"/><block path="database/xsl:for&#x2D;each/table/xsl:if" x="155" y="41"/><block path="database/xsl:for&#x2D;each/table/xsl:if/xsl:for&#x2D;each" x="225" y="71"/></template></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->